<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
  components: {},
  data() {
    return {
      appWindow: window,
      form: {
        // 是否开启业绩奖励 1：开启，2：关闭
        achievement_switch: 1,
        // 结算周期（周，月，季度，年度）
        settle_cycle: "月",
        // 励时间ex：16:00 ，每日某个时分
        award_time: "",
      },

      load: false,

      timeList: ["0:00", "1:00", "2:00", "3:00", "4:00", "5:00", "6:00", "7:00", "8:00", "9:00", "10:00", "11:00",
                "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00"],
    };
  },
  methods: {
    // 验证 
    validate() {
      return new Promise((resolve, reject) => {
        this.$refs["editForm"].validate((valid) => {
            valid ? resolve(true) : resolve(false)
        });
      });
    },
    async sum() {
      if (!await this.validate()) {
        return
      }
      this.load = true;
      let res = await this.$vFN.Http.post({
        url: "plugin/team-dividend/admin/setting/setAchievement",
        data: this.form,
      }, window);
      if(res.code == 200) {
        this.$vFN.Tools.messageSuccess("操作成功")
        this.getData();
      }
    },

    async getData() {
      this.load = true;
      let res = await this.$vFN.Http.post({
        url: "plugin/team-dividend/admin/setting/getBase",
      }, window);
      if(res.data.achievement_set != null) {
        this.form.achievement_switch = JSON.parse(res.data.achievement_set.achievement_switch);
        this.form.award_time = res.data.achievement_set.award_time;
        this.form.settle_cycle = res.data.achievement_set.settle_cycle;
      }
      this.load = false;
    },
    
    // 初始化
    async init() {
      this.getData();
    },
  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>